/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 */

import { FileUtil } from '../../utils/file-util.js';
import { JavaCommandBuilder } from '../java-command-builder.js';

/**
 * 新签名工具hap-sign-tool的签名options
 *
 * @since 2022/03/01
 */
export class NewSigningOptions extends JavaCommandBuilder {
  sign(): NewSigningOptions {
    this.commandList.push('sign-app');
    return this;
  }

  addMode(mode: string): NewSigningOptions {
    this.commandList.push('-mode');
    this.commandList.push(mode);
    return this;
  }

  addProfileFile(profile: string): NewSigningOptions {
    FileUtil.checkPathLength(profile);
    this.commandList.push('-profileFile');
    this.commandList.push(profile);
    return this;
  }

  profileSigned(): NewSigningOptions {
    this.commandList.push('-profileSigned');
    this.commandList.push('1');
    return this;
  }

  addInForm(inFormType: string): NewSigningOptions {
    this.commandList.push('-inForm');
    this.commandList.push(inFormType);
    return this;
  }

  addSignAlg(signAlg: string): NewSigningOptions {
    this.commandList.push('-signAlg');
    this.commandList.push(signAlg);
    return this;
  }

  addKeyAlias(privateKey: string): NewSigningOptions {
    this.commandList.push('-keyAlias');
    this.commandList.push(privateKey);
    return this;
  }

  addKeyStoreFile(keyStoreFile: string): NewSigningOptions {
    FileUtil.checkPathLength(keyStoreFile);
    this.commandList.push('-keystoreFile');
    this.commandList.push(keyStoreFile);
    return this;
  }

  addKeyStorePwd(keyStorePwd: string): NewSigningOptions {
    this.commandList.push('-keystorePwd');
    this.commandList.push(keyStorePwd);
    return this;
  }

  addKeyPwd(keyAliasPwd: string): NewSigningOptions {
    this.commandList.push('-keyPwd');
    this.commandList.push(keyAliasPwd);
    return this;
  }

  addAppCertFile(certPath: string): NewSigningOptions {
    FileUtil.checkPathLength(certPath);
    this.commandList.push('-appCertFile');
    this.commandList.push(certPath);
    return this;
  }

  addInputFile(inputFile: string): NewSigningOptions {
    FileUtil.checkPathLength(inputFile);
    this.commandList.push('-inFile');
    this.commandList.push(inputFile);
    return this;
  }

  addOutputFile(outputFile: string): NewSigningOptions {
    FileUtil.checkPathLength(outputFile);
    this.commandList.push('-outFile');
    this.commandList.push(outputFile);
    return this;
  }
}
